/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import { concat } from "lodash-es";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import { pageAll as getVideoTypeList } from "$/gq/video-monitoring/api/gqVideoType.ts";
import MaDictSelect from "@/components/ma-dict-picker/ma-dict-select.vue";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: t("video-monitoring.camera.fields.name"),
      prop: "name",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.name"),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("video-monitoring.camera.validation.name_required"),
          },
          {
            max: 100,
            message: t("video-monitoring.camera.validation.name_max"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.short_name"),
      prop: "short_name",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.short_name"),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t(
              "video-monitoring.camera.validation.short_name_required"
            ),
          },
          {
            max: 50,
            message: t("video-monitoring.camera.validation.short_name_max"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.type"),
      prop: "type",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getVideoTypeList,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            // 过滤type为1的数据（点位类型）
            return response.data.list.map((item: any) => ({
              label: item.name,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择摄像头类型",
        clearable: true,
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: "请选择摄像头类型",
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.device_code"),
      prop: "device_code",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.device_code"),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t(
              "video-monitoring.camera.validation.device_code_required"
            ),
          },
          {
            max: 50,
            message: t("video-monitoring.camera.validation.device_code_max"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.device_serial"),
      prop: "device_serial",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.device_serial"),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t(
              "video-monitoring.camera.validation.device_serial_required"
            ),
          },
          {
            max: 100,
            message: t("video-monitoring.camera.validation.device_serial_max"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.manufacturer"),
      prop: "manufacturer",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.manufacturer"),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t(
              "video-monitoring.camera.validation.manufacturer_required"
            ),
          },
          {
            max: 100,
            message: t("video-monitoring.camera.validation.manufacturer_max"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.ip_address"),
      prop: "ip_address",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.ip_address"),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t(
              "video-monitoring.camera.validation.ip_address_required"
            ),
          },
          {
            type: "string",
            pattern:
              /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
            message: t("video-monitoring.camera.validation.ip_address_format"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.port"),
      prop: "port",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.port"),
        min: 1,
        max: 65535,
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("video-monitoring.camera.validation.port_required"),
          },
          {
            type: "number",
            min: 1,
            max: 65535,
            message: t("video-monitoring.camera.validation.port_range"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.username"),
      prop: "username",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.username"),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("video-monitoring.camera.validation.username_required"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.password"),
      prop: "password",
      render: "input",
      renderProps: {
        type: "password",
        placeholder: t("video-monitoring.camera.placeholder.password"),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("video-monitoring.camera.validation.password_required"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.play_url_full"),
      prop: "play_url",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.play_url"),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("video-monitoring.camera.validation.play_url_required"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.location"),
      prop: "location",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.location"),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("video-monitoring.camera.validation.location_required"),
          },
        ],
      },
    },
    {
      label: t("video-monitoring.camera.fields.longitude"),
      prop: "longitude",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.longitude"),
        precision: 6,
        min: -180,
        max: 180,
      },
    },
    {
      label: t("video-monitoring.camera.fields.latitude"),
      prop: "latitude",
      render: "input",
      renderProps: {
        placeholder: t("video-monitoring.camera.placeholder.latitude"),
        precision: 6,
        min: -90,
        max: 90,
      },
    },
    {
      label: t("video-monitoring.camera.fields.status"),
      prop: "status",
      render: () => MaDictSelect,
      renderProps: {
        placeholder: t("form.pleaseInput", {
          msg: t("video-monitoring.camera.fields.status"),
        }),
        data: [
          { label: t("video-monitoring.camera.status.online"), value: 1 },
          { label: t("video-monitoring.camera.status.offline"), value: 0 },
        ],
        clearable: true,
        multiple: false,
      },
    },
  ]);
}
